#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

import bs4
import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions


date = re.compile(r'(?P<month>\d{1,2})月(?P<day>\d{1,2})日')

HOME = r'http://www.99mingxing.com'
url = r'http://www.99mingxing.com/mxda/nadi'

resp = requests.get(url)


options = Options()
# options.set_headless(headless=True)
driver = webdriver.Chrome(chrome_options=options)

options.add_argument('user-agent="Mozilla/5.0"')

def get_data(url):
    print(url)
    resp = requests.get(url)
    soup = bs4.BeautifulSoup(resp.content, 'lxml')
    info = soup.find('div', {'class': 'jianjie-ms'})
    if info:
        m = date.search(info.text)
        if m:
            return {a.text.strip(): (int(m['month']), int(m['day']))}

data = {}

k =1
driver = webdriver.Chrome(chrome_options=options)
driver.get(url)

# wait = WebDriverWait(driver, 5)
# wait.until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, 'member')))

soup = bs4.BeautifulSoup(driver.page_source, 'lxml')

for a in soup.find('div', {'class': 'border'}).find_all('a'):

    url = HOME + a['href']
    data0 = get_data(url)
    if data0:
        data.update(data0)
print(data)
driver.quit()

